ARG_TERMINATOR
};
+
+/************************************************************************/
+/* SHPOpenGpsbabel() */
+/************************************************************************/
+
+SHPHandle SHPAPI_CALL
+SHPOpenGpsbabel( const QString& pszLayer, const char * pszAccess )
+
+{
+ SAHooks sHooks;
+
+#ifdef SHPAPI_UTF8_HOOKS
+ SASetupUtf8Hooks( &sHooks );
+ return SHPOpenLL( pszLayer.toUtf8().constData(), pszAccess, &sHooks );
+#else
+ SASetupDefaultHooks( &sHooks );
+ return SHPOpenLL( qPrintable(pszLayer), pszAccess, &sHooks );
+#endif
+
+}
+
+/************************************************************************/
+/* SHPCreateGpsbabel() */
+/* */
+/* Create a new shape file and return a handle to the open */
+/* shape file with read/write access. */
+/************************************************************************/
+
+SHPHandle SHPAPI_CALL
+SHPCreateGpsbabel( const QString& pszLayer, int nShapeType )
+
+{
+ SAHooks sHooks;
+
+#ifdef SHPAPI_UTF8_HOOKS
+ SASetupUtf8Hooks( &sHooks );
+ return SHPCreateLL( pszLayer.toUtf8().constData(), nShapeType, &sHooks );
+#else
+ SASetupDefaultHooks( &sHooks );
+ return SHPCreateLL( qPrintable(pszLayer), nShapeType, &sHooks );
+#endif
+
+}
+
+/************************************************************************/
+/* DBFOpenGpsbabel() */
+/* */
+/* Open a .dbf file. */
+/************************************************************************/
+
+DBFHandle SHPAPI_CALL
+DBFOpenGpsbabel( const QString& pszFilename, const char * pszAccess )
+
+{
+ SAHooks sHooks;
+
+#ifdef SHPAPI_UTF8_HOOKS
+ SASetupUtf8Hooks( &sHooks );
+ return DBFOpenLL( pszFilename.toUtf8().constData(), pszAccess, &sHooks );
+#else
+ SASetupDefaultHooks( &sHooks );
+ return DBFOpenLL( qPrintable(pszFilename), pszAccess, &sHooks );
+#endif
+
+}
+
+/************************************************************************/
+/* DBFCreateExGpsbabel() */
+/* */
+/* Create a new .dbf file. */
+/************************************************************************/
+
+DBFHandle SHPAPI_CALL
+DBFCreateExGpsbabel( const QString& pszFilename, const char* pszCodePage )
+
+{
+ SAHooks sHooks;
+
+#ifdef SHPAPI_UTF8_HOOKS
+ SASetupUtf8Hooks( &sHooks );
+ return DBFCreateLL( pszFilename.toUtf8().constData(), pszCodePage , &sHooks );
+#else
+ SASetupDefaultHooks( &sHooks );
+ return DBFCreateLL( qPrintable(pszFilename), pszCodePage , &sHooks );
+#endif
+
+}
+
+/************************************************************************/
+/* DBFCreateGpsbabel() */
+/* */
+/* Create a new .dbf file with default code page LDID/87 (0x57) */
+/************************************************************************/
+
+DBFHandle SHPAPI_CALL
+DBFCreateGpsbabel( const QString& pszFilename )
+
+{
+ return DBFCreateExGpsbabel( pszFilename, "LDID/87" ); // 0x57
+}
+
static
void dump_fields(void)
{
{
ifname = fname;
// TODO: The .prj file can define the the coordinate system and projection information.
- ihandle = SHPOpen(qPrintable(fname), "rb");
+ ihandle = SHPOpenGpsbabel(fname, "rb");
if (ihandle == NULL) {
fatal(MYNAME ": Cannot open shp file %s for reading\n", qPrintable(ifname));
}
- ihandledb = DBFOpen(qPrintable(fname), "rb");
+ ihandledb = DBFOpenGpsbabel(fname, "rb");
if (ihandledb == NULL) {
fatal(MYNAME ": Cannot open dbf file %s for reading\n", qPrintable(ifname));
}
switch (global_opts.objective) {
case wptdata:
case unknown_gpsdata:
- ohandle = SHPCreate(qPrintable(ofname), SHPT_POINT);
+ ohandle = SHPCreateGpsbabel(ofname, SHPT_POINT);
if (ohandle == NULL) {
fatal(MYNAME ": Cannot open shp file %s for writing\n",
qPrintable(ofname));
}
- ohandledb = DBFCreateEx(qPrintable(ofname), "UTF-8\n");
+ ohandledb = DBFCreateExGpsbabel(ofname, "UTF-8\n");
if (ohandledb == NULL) {
fatal(MYNAME ": Cannot open dbf file %s for writing\n",
qPrintable(ofname));
break;
case rtedata:
case trkdata:
- ohandle = SHPCreate(qPrintable(ofname), SHPT_ARC);
+ ohandle = SHPCreateGpsbabel(ofname, SHPT_ARC);
if (ohandle == NULL) {
fatal(MYNAME ": Cannot open shp file %s for writing\n",
qPrintable(ofname));
}
- ohandledb = DBFCreateEx(qPrintable(ofname), "UTF-8\n");
+ ohandledb = DBFCreateExGpsbabel(ofname, "UTF-8\n");
if (ohandledb == NULL) {
fatal(MYNAME ": Cannot open dbf file %s for writing\n",
qPrintable(ofname));
errorcount=`expr $errorcount + 1`
fi
+# test input file name mangling with shape files
+ echo "testing input file name with shape files"
+ rm -f ${TMPDIR}/test_encoding_file*
+ for ext in cpg dbf prj shp shx
+ do
+ cp ${REFERENCE}/gis.osm_railways_free_1.${ext} ${TMPDIR}/${filenamebase}.${ext}
+ done
+ ${PNAME} -r -i shape -f ${TMPDIR}/${filenamebase}.shp -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
+ echo "ERROR: The input file name was mangled."
+ errorcount=`expr $errorcount + 1`
+ }
+
+# test output file name mangling with shape files
+ echo "testing output file name with shape files"
+ rm -f ${TMPDIR}/test_encoding_file*
+ ${PNAME} -r -i gpx -f ${REFERENCE}/bounds-test.gpx -o shape -F ${TMPDIR}/${filenamebase}.shp
+ for ext in cpg dbf shp shx
+ do
+ count=$(ls -1 -l ${TMPDIR}/${filenamebase}.${ext} 2>/dev/null | wc -l)
+ if [ $count -lt 1 ]; then
+ echo "ERROR: The output file name was mangled."
+ errorcount=`expr $errorcount + 1`
+ fi
+ done
+ rm -f ${TMPDIR}/test_encoding_file*
+ ${PNAME} -w -i gpx -f ${REFERENCE}/bounds-test.gpx -o shape -F ${TMPDIR}/${filenamebase}.shp
+ for ext in cpg dbf shp shx
+ do
+ count=$(ls -1 -l ${TMPDIR}/${filenamebase}.${ext} 2>/dev/null | wc -l)
+ if [ $count -lt 1 ]; then
+ echo "ERROR: The output file name was mangled."
+ errorcount=`expr $errorcount + 1`
+ fi
+ done
+
# TODO: add tests to cover formats that use other open methods.
-# for example shape files.
else
echo "$0 cannot run without the en_US.iso88591 locale."
errorcount=`expr $errorcount + 1`
fi
+# test input file name mangling with shape files
+ echo "testing input file name with shape files"
+ rm -f ${TMPDIR}/test_encoding_file*
+ for ext in cpg dbf prj shp shx
+ do
+ cp ${REFERENCE}/gis.osm_railways_free_1.${ext} ${TMPDIR}/${filenamebase}.${ext}
+ done
+ ${PNAME} -r -i shape -f ${TMPDIR}/${filenamebase}.shp -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
+ echo "ERROR: The input file name was mangled."
+ errorcount=`expr $errorcount + 1`
+ }
+
+# test output file name mangling with shape files
+ echo "testing output file name with shape files"
+ rm -f ${TMPDIR}/test_encoding_file*
+ ${PNAME} -r -i gpx -f ${REFERENCE}/bounds-test.gpx -o shape -F ${TMPDIR}/${filenamebase}.shp
+ for ext in cpg dbf shp shx
+ do
+ count=$(ls -1 -l ${TMPDIR}/${filenamebase}.${ext} 2>/dev/null | wc -l)
+ if [ $count -lt 1 ]; then
+ echo "ERROR: The output file name was mangled."
+ errorcount=`expr $errorcount + 1`
+ fi
+ done
+ rm -f ${TMPDIR}/test_encoding_file*
+ ${PNAME} -w -i gpx -f ${REFERENCE}/bounds-test.gpx -o shape -F ${TMPDIR}/${filenamebase}.shp
+ for ext in cpg dbf shp shx
+ do
+ count=$(ls -1 -l ${TMPDIR}/${filenamebase}.${ext} 2>/dev/null | wc -l)
+ if [ $count -lt 1 ]; then
+ echo "ERROR: The output file name was mangled."
+ errorcount=`expr $errorcount + 1`
+ fi
+ done
+
# TODO: add tests to cover formats that use other open methods.
-# for example shape files.
else
echo "$0 cannot run without the UTF-8 charmap."